package org.lanqiao.webfm.service;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javacommon.base.BaseService;
import javacommon.base.EntityDao;

import org.lanqiao.webfm.dao.TypeDao;
import org.lanqiao.webfm.model.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*@Author zhengwei
**/
public class TypeService extends BaseService<Type> {
	private static final Logger LOGGER = LoggerFactory.getLogger(TypeService.class);
	private TypeService(){}
	private static TypeService instance = new TypeService();
	public static TypeService getInstance(){
		return instance;
	}

	private TypeDao typeDao = TypeDao.getInstance();
	
	public EntityDao getEntityDao() {
		return this.typeDao;
	}

	public Map<Type, List<Type>> findTypeInfo() throws SQLException {
		Map<Type, List<Type>> map = new HashMap<Type, List<Type>>();
		//查出一级分类
		List<Type> level1 = typeDao.findFirstLevel();
		//迭代一级分类,得到其对应的二级分类
		for (Type type : level1) {
			List<Type> level2 = typeDao.findByPtype(type);
			map.put(type, level2);
		}
		return map;
	}
	
}
